//package com.xiaocikuai.smallchunks.controller.Product;
//
//
//import com.xiaocikuai.smallchunks.entity.Product.Link;
//import com.xiaocikuai.smallchunks.entity.User.Duser;
//import com.xiaocikuai.smallchunks.service.Product.impl.LinkServiceImpl;
//import com.xiaocikuai.smallchunks.service.User.impl.DuserServiceImpl;
//import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
//import jakarta.annotation.Resource;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//
///**
// * <p>
// * 外部链接获取 前端控制器
// * </p>
// *
// * @author author1
// * @since 2024-07-18
// */
//@RestController
//@RequestMapping("/link")
//public class LinkController {
//
//
//    @Resource
//    private LinkServiceImpl linkService;
//
//    @PostMapping("/add")
//    public Resultd addLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
//        if (linkService.save(link)) {
//            return Resultd.ok().data("info", "注册成功");
//        } else {
//            return Resultd.error().data("info", "注册失败");
//        }
//    }
//
//    @PostMapping("/delete")
//    public Resultd deleteLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
//        if (linkService.removeById(link.getId())) {
//            return Resultd.ok().data("info", "删除成功");
//        } else {
//            return Resultd.error().data("info", "删除失败");
//        }
//    }
//
//    @PostMapping("/update")
//    public Resultd updateLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
//        if (linkService.updateById(link)) {
//            return Resultd.ok().data("info", "更新成功");
//        } else {
//            return Resultd.error().data("info", "更新失败");
//        }
//    }
//
//
//
//    @PostMapping("/select")
//    public Resultd selectLinkList(@RequestHeader("Authorization") String token, @RequestBody Link link) {
//        List<Link> links = linkService.list();
//        if (links!= null) {
//            return Resultd.ok().data("info", links);
//        } else {
//            return Resultd.error().data("info", "未找到对应记录");
//        }
//    }
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//}
package com.xiaocikuai.smallchunks.controller.Product;

import com.xiaocikuai.smallchunks.entity.Product.Link;
import com.xiaocikuai.smallchunks.service.Product.impl.LinkServiceImpl;
import com.xiaocikuai.smallchunks.utils.resultd.Resultd;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 外部链接获取 前端控制器
 * </p>
 *
 * @author author1
 * @since 2024-07-18
 */
@Api(tags = "链接管理控制器")
@RestController
@RequestMapping("/link")
public class LinkController {

    @Resource
    private LinkServiceImpl linkService;

    @ApiOperation(value = "添加链接")
    @PostMapping("/add")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "link", value = "链接信息", required = true, dataType = "Link", paramType = "body")
    })
    public Resultd addLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
        if (linkService.save(link)) {
            return Resultd.ok().data("info", "注册成功");
        } else {
            return Resultd.error().data("info", "注册失败");
        }
    }

    @ApiOperation(value = "删除链接")
    @PostMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "link", value = "链接信息", required = true, dataType = "Link", paramType = "body")
    })
    public Resultd deleteLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
        if (linkService.removeById(link.getId())) {
            return Resultd.ok().data("info", "删除成功");
        } else {
            return Resultd.error().data("info", "删除失败");
        }
    }

    @ApiOperation(value = "更新链接")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "link", value = "链接信息", required = true, dataType = "Link", paramType = "body")
    })
    public Resultd updateLink(@RequestHeader("Authorization") String token, @RequestBody Link link) {
        if (linkService.updateById(link)) {
            return Resultd.ok().data("info", "更新成功");
        } else {
            return Resultd.error().data("info", "更新失败");
        }
    }

    @ApiOperation(value = "查询链接列表")
    @PostMapping("/select")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "授权令牌", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "link", value = "链接信息", required = true, dataType = "Link", paramType = "body")
    })
    public Resultd selectLinkList(@RequestHeader("Authorization") String token, @RequestBody Link link) {
        List<Link> links = linkService.list();
        if (links!= null) {
            return Resultd.ok().data("info", links);
        } else {
            return Resultd.error().data("info", "未找到对应记录");
        }
    }
}